import * as feishuService from '@/api/service/FeishuService'
const globalVal = globalThis as any

/**
 * 初始化飞书
 * @returns
 */
export async function initFeishu():Promise<any>{
  if(!globalVal.tableConfig){
    const resp = await feishuService.appTables();
    const tables = resp.data.items
    const tableConfig: TableConfig = {
      category: '',
      daily: '',
      selection: '',
      account: '',
      system: ''
    }
    tables.forEach(table => {
      if(table.name === '商品分类表'){
        tableConfig.category = table.table_id
      }
      else if(table.name === '日常选品共用表'){
        tableConfig.daily = table.table_id
      }
      else if(table.name === '跟单选品表'){
        tableConfig.selection = table.table_id
      }
      else if(table.name === '账号偏好表'){
        tableConfig.account = table.table_id
      }
      else if(table.name === '系统表'){
        tableConfig.system = table.table_id
      }
    })
    globalVal.tableConfig = tableConfig
  }

  if(!globalVal.tableConfig.category){
    // TODO
  }
  if(!globalVal.tableConfig.daily){
    // TODO
  }
  if(!globalVal.tableConfig.selection){
    // TODO
  }



  return globalVal.tableConfig;
}
